package com.DataFactory.TaskManagement.controller;

import com.DataFactory.TaskManagement.common.result.PageResult;
import com.DataFactory.TaskManagement.common.result.Result;
import com.DataFactory.TaskManagement.model.entity.TaskArrangement;
import com.DataFactory.TaskManagement.model.form.TaskArrangementForm;
import com.DataFactory.TaskManagement.model.query.TaskArrangementQuery;
import com.DataFactory.TaskManagement.model.vo.TaskArrangementPageVO;
import com.DataFactory.TaskManagement.service.TaskArrangeService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@RestController
@RequiredArgsConstructor
@RequestMapping("/api/taskArrange")
public class TaskArrangeController {

    private final TaskArrangeService taskArrangeService;

    /**
     * 获取任务分页列表
     * @param queryParams
     * @return
     */
    @GetMapping("/page")
    public PageResult<TaskArrangementPageVO> getTaskPage(@ParameterObject @Valid TaskArrangementQuery queryParams){
        Page<TaskArrangementPageVO> result= taskArrangeService.getTaskPage(queryParams);
        return PageResult.success(result);
    }

    @GetMapping("/getList")
    public Result getList(){
        //拿到list
        List<TaskArrangement> list = taskArrangeService.getList();
        return Result.success(list);
    }

    /***
     * 添加任务方式1
     * @param form
     * @return
     */
    @PostMapping("/add")
    public Result addTask(@RequestBody TaskArrangementForm form){
        Boolean result = taskArrangeService.addTaskArrangement(form);
        return Result.judge(result);
    }

    /***
     * 指派单个任务添加
     * @param taskArrangement
     * @return
     */
    @PostMapping("/addOne")
    public Result addOneTaskArrangement(@RequestBody TaskArrangement taskArrangement){
        System.out.println("taskArrangement:"+taskArrangement);
        Boolean result = taskArrangeService.addTaskArrangement(taskArrangement);
        return Result.judge(result);
    }

    @PutMapping("/update/{id}")
    public Result updateTask(@PathVariable Integer id, @RequestBody @Valid TaskArrangementForm taskArrangementForm) {
        Boolean result =taskArrangeService.updateTaskArrangement(id,taskArrangementForm);
        return Result.judge(result);
    }

    @DeleteMapping("/delete/{ids}")
    public Result deleteTask(@PathVariable String ids){
        Boolean result = taskArrangeService.deleteTaskArrangments(ids);
        return Result.judge(result);
    }

    @GetMapping("/{id}/form")
    public Result getTaskArrangementForm(@PathVariable Integer id){
        TaskArrangementForm result  = taskArrangeService.getTaskArrangementForm(id);
        return Result.success(result);
    }

}
